//
//  TiXianInfoViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/15.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "TiXianInfoViewController.h"
#import "JTCSM.h"
#import "ZhangDanModel.h"
#import "ZhangdanMingxinTableViewCell.h"
@interface TiXianInfoViewController ()<UIAlertViewDelegate,UITableViewDelegate,UITableViewDataSource>
{
    NSMutableArray *title1array;
    UITableView *_tableview;
    NSString *pageOne;
}
@end

@implementation TiXianInfoViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.hidden = NO;
    [df isRemoveTarbar:YES];
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    pageOne = @"";
    [self layoutTableView];
    [self theRequesttypeOne];
    // Do any additional setup after loading the view.
}

- (void)layoutTableView{
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERHeight)];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self.view addSubview:_tableview];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    _tableview.backgroundColor = RGBACOLOR(241, 241, 241, 1);
    [self setUpTableView];
    //    view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
}

- (void)setUpTableView{
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    [_tableview addHeaderWithTarget:self action:@selector(headerRereshing)];
    
    // 上拉加载
    [_tableview addFooterWithTarget:self action:@selector(footerRereshing)];
    
}
- (void)headerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
        [self theRequesttypeOne];
            
    });
}
- (void)footerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
       
       [self theRequesttypeOneMore];
});
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return title1array.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *cellid = [NSString stringWithFormat:@"iii%ld",(long)indexPath.row];
    
    ZhangdanMingxinTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[ZhangdanMingxinTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid];
    }
    if (indexPath == nil || indexPath.row >=(title1array.count)) {
        return cell;
    }
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    ZhangDanModel *model = title1array[indexPath.row];
    [cell setValueWithZhangDanModel:model mytype:ZhangdanMingxinTableViewCellTiXian];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [ZhangdanMingxinTableViewCell whc_CellHeightForIndexPath:indexPath tableView:tableView];
}


- (void)theRequesttypeOne{
    //    CreditCard/repay CreditCard/expense
    
    [title1array removeAllObjects];
    title1array = nil;
    title1array = [NSMutableArray array];
    
    LoadData *request = [[LoadData alloc]init];
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"UserBill/cash") withDict:@{@"token":KTokenString} superView:nil isAddtag:NO Block:^(id result) {
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            pageOne = KResultOfKey(@"p");
            NSArray *bannerArr = [KResultOfKey(@"data") objectForKey:@"list"];
            for (NSDictionary *bannerdict in bannerArr) {
                ZhangDanModel *model = [ZhangDanModel whc_ModelWithJson:bannerdict];
                [title1array addObject:model];
            }
            
            [_tableview reloadData];
            [_tableview headerEndRefreshing];
        }
    }];
    
}

- (void)theRequesttypeOneMore{
    LoadData *request = [[LoadData alloc]init];
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"UserBill/cash") withDict:@{@"token":KTokenString,@"p":pageOne} superView:nil isAddtag:NO Block:^(id result) {
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            
            pageOne = KResultOfKey(@"p");
            NSArray *bannerArr = [KResultOfKey(@"data") objectForKey:@"list"];
            for (NSDictionary *bannerdict in bannerArr) {
                ZhangDanModel *model = [ZhangDanModel whc_ModelWithJson:bannerdict];
                [title1array addObject:model];
            }
            
            [_tableview reloadData];
            [_tableview footerEndRefreshing];
        }
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
